package com.example.killer.simpleadapterdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private ListView listView;
    private List<Map<String, Object>> values;
    private SimpleAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        listView = (ListView) findViewById(R.id.lv_listView);

        values = new ArrayList<>();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yy-MM-dd HH-mm-ss");
        String time = simpleDateFormat.format(new Date());
        for (int i = 0;i<30;i++){
            Map<String, Object> map = new HashMap<>();
            map.put("title", "测试标题" + i);
            map.put("time", "发布时间：" + time );

            map.put("number", 100 + i);
            values.add(map);
        }

        adapter = new SimpleAdapter(this,values,R.layout.fill_lisvtew,new String[]{"title","time","number"},new int[]{R.id.tv_title,R.id.tv_time,R.id.tv_number});
        listView.setAdapter(adapter);

    }
}
